﻿/**
 * Licensed to Open-Ones Group under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Open-Ones Group licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a
 * copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
namespace IPresenter
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;

    /// <summary>
    /// This class includes commands which is uesd in application
    /// </summary>
    public class CommonCommand
    {
        /// <summary>
        /// Determine whether command is in list command in application
        /// </summary>
        /// <param name="nameCommand">Name of command</param>
        /// <returns>
        /// true: a command exist
        /// false:a command not exist
        /// </returns>
        public static bool IsContain(string nameCommand)
        {
            List<string> lstCommand = new List<string>();
            lstCommand.Add(PresentCommand.NEXT_SLIDE);
            lstCommand.Add(PresentCommand.PREVIOUS_SLIDE);
            lstCommand.Add(PresentCommand.FULL_SCREEN);
            lstCommand.Add(PresentCommand.END_FULL_SCREEN);
            return lstCommand.Contains(nameCommand);
        }

        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="command">Name of command</param>
        public static void ExecuteCommand(string command)
        {
            if (OptionIPresenter.Mode == OptionIPresenter.MODE_DEFAULT)
            {
                bool blnPowerPoint = PowerPointSupport.DetermineWindowOrPresentation();
                bool blnOpenOffice = OpenOfficeSupport.DeterminePresentation();
                if (blnOpenOffice == true)
                {
                    OptionIPresenter.KindOfPresentation = OptionIPresenter.KIND_OPENOFFICE;
                }

                if (blnPowerPoint == true)
                {
                    OptionIPresenter.KindOfPresentation = OptionIPresenter.KIND_POWERPOINT;
                }

                if (blnOpenOffice == false && blnPowerPoint == false)
                {
                    return;
                }
            }

            if (OptionIPresenter.Mode == OptionIPresenter.MODE_EXTEND)
            {
            }

            switch (command)
            {
                case PresentCommand.NEXT_SLIDE:
                    if (OptionIPresenter.KindOfPresentation == OptionIPresenter.KIND_POWERPOINT)
                    {
                        PowerPointSupport.NextSlide();
                    }
                    else
                    {
                        OpenOfficeSupport.NextSlide();
                    }

                    break;
                case PresentCommand.PREVIOUS_SLIDE:
                    if (OptionIPresenter.KindOfPresentation == OptionIPresenter.KIND_POWERPOINT)
                    {
                        PowerPointSupport.PreviousSlide();
                    }
                    else
                    {
                        OpenOfficeSupport.PreviousSlide();
                    }

                    break;
                case PresentCommand.FULL_SCREEN:
                    if (OptionIPresenter.KindOfPresentation == OptionIPresenter.KIND_POWERPOINT)
                    {
                        PowerPointSupport.FullScreen();
                    }
                    else
                    {
                        OpenOfficeSupport.FullScreen();
                    }

                    break;
                case PresentCommand.END_FULL_SCREEN:
                    if (OptionIPresenter.KindOfPresentation == OptionIPresenter.KIND_POWERPOINT)
                    {
                        PowerPointSupport.EndFullScreen();
                    }
                    else
                    {
                        OpenOfficeSupport.EndFullScreen();
                    }

                    break;
                case PresentCommand.GO_TO_SLIDE:
                    if (OptionIPresenter.KindOfPresentation == OptionIPresenter.KIND_POWERPOINT)
                    {
                        PowerPointSupport.GoToSlide(PowerPointSupport.SlideNumber);
                    }
                    else
                    {
                        OpenOfficeSupport.GoToSlide(OpenOfficeSupport.SlideNumber.ToString());
                    }

                    break;
                default:
                    Logs.WriteErrorMessage("Command is not exist");
                    break;
            }
        }
    }
}